{% extends 'home_page/base_index.html' %}
{% load static %}


{% block show_body %}
<section class="section">
    <div class="row">
        <div class="col-xl-12 col-md-12 col-sm-12">
            <div class="card">
                <div class="card-content">
                    <div class="card-body">
                        <h4 class="card-title">{{ interview.job_posting.title }}&nbsp&nbsp&nbsp&nbsp{{ interview.job_posting.salary_range }}</h4>
                        <h6 class="card-subtitle">{{ interview.organization.name }}</h6>
                    </div>
                    <div class="card-body">
                        <h6 class="card-subtitle">职位描述</h6>
                        <p class="card-text">
                            {{ interview.job_posting.description }}
                        </p>
                        <p class="card-text">
                            {{ interview.job_posting.requirements }}
                        </p>
                    </div>
                    <div class="card-body">
                        <h6 class="card-subtitle">工作地点</h6>
                        <p class="card-text">
                            {{ interview.job_posting.location }}&nbsp&nbsp&nbsp&nbsp截止日期：{{ interview.job_posting.deadline }}
                        </p>
                    </div>
                </div>
            </div>
            <div class="card">
                <div class="card-content">
                    <div class="card-body">
                        <h4 class="card-title">面试通过</h4>

                        <form id="interview_form" class="form">

                            <div class="form-body">
                                <div class="form-group">
                                    <label for="feedback1" class="sr-only">姓名</label>
                                    <input required
                                        type="text" id="feedback1" class="form-control" value="{{ interview.student.stu_name }}"
                                        name="stu_name" disabled>
                                </div>
                                <div class="form-group">
                                    <label for="feedback4" class="sr-only">电话号码</label>
                                    <input type="text" id="feedback4" class="form-control" disabled
                                                       value="{{ interview.student.phone_number }}" name="phone_number">
                                </div>
                                <div class="form-group">
                                    <label for="feedback2" class="sr-only">Email</label>
                                    <input type="email" id="feedback2" class="form-control" value="{{ interview.organization.email }}"
                                        name="email" disabled>
                                </div>
                                <div class="form-group">
                                    <label for="gender" class="sr-only">性别</label>
                                    <input
                                        type="text" id="gender" class="form-control" value="{{ interview.student.gender}}"
                                      disabled>
                                </div>
                                <div class="form-group">
                                    <label for="status" class="sr-only">面试状态</label>
                                    <input
                                        type="text" id="status" class="form-control" value="{{ interview.status}}"
                                      disabled>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <div class="card">
                    <div class="card-header">
                        <h4 class="card-title">发布实习通知</h4>
                        <p class="card-text">
                            面试申请已通过，请企业发布实习通知！
                        </p>
                    </div>
                    <div class="card-content">
                        <div class="card-body">
                            <form id="form" class="form">
                                {% csrf_token %}
                                <div class="row">
                                    <div class="col-md-6 col-12">
                                        <div class="form-group">
                                            <label for="first-name-column">实习地点</label>
                                            <input name="location" type="text" id="first-name-column" class="form-control"></div>
                                    </div>
                                    <div class="col-md-6 col-12">
                                        <div class="form-group"><label for="last-name-column">注意事项</label><input type="text" id="requirements" class="form-control" name="requirements" value="无"></div>
                                    </div>
                                    <div class="col-md-6 col-12">
                                        <div class="form-group">
                                            <label for="city-column">实习期</label>
                                            <input type="text" id="duration" class="form-control" required name="duration">
                                        </div>
                                    </div>
                                    <div class="col-md-6 col-12">
                                        <div class="form-group"><label for="country-floating">实习薪资</label><input type="text" required id="salary_range" class="form-control" name="salary_range"></div>
                                    </div>
                                    <div class="col-md-6 col-12">
                                        <div class="form-group"><label for="email-id-column">开始日期</label><input type="date" required id="start_date" class="form-control" name="start_date"></div>
                                    </div>
                                    <div class="col-md-6 col-12">
                                        <div class="form-group"><label for="email-id-column">结束日期</label><input type="date" required id="end_date" class="form-control" name="end_date"></div>
                                    </div>
                                    <div class="form-group col-12">
                                        <div class="form-check">
                                            <input type="text" hidden="hidden" name="description" value="{{ interview.job_posting.description }}">
                                            <input type="text" hidden="hidden" name="requirements" value="{{ interview.job_posting.requirements }}">
                                            <input type="text" hidden="hidden" name="organization_id" value="{{ interview.organization.id }}">
                                            <input type="text" hidden="hidden" name="student_id" value="{{ interview.student.id }}">
                                            <input type="text" hidden="hidden" name="title" value="{{ interview.job_posting.title }}">
                                        </div>
                                    </div>
                                    <div class="col-12 d-flex justify-content-end">
                                        <button type="submit" class="btn btn-primary me-1 mb-1">发布</button>
                                        <button type="reset" class="btn btn-light-secondary me-1 mb-1">重置</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
        </div>
    </div>
</section>
{% endblock %}


{% block show_user %}
    {% if user_label == 1 %}
        {# 当学生用户登录的时候显示学生的姓名和学号 #}
        <div class="card">
            <div class="card-body py-4 px-5">
                <div class="d-flex align-items-center">
                    {# 性别不同默认头像不一样 #}
                    <div class="avatar avatar-xl">
                        {% if gender == 'female' %}
                            <img src="{% static 'picture/5.jpg' %}" alt="Face female">
                        {% else %}
                            <img src="{% static 'picture/2.jpg' %}" alt="Face male">
                        {% endif %}
                    </div>
                    {# 加载学生的姓名和学号 #}
                    <div class="ms-3 name"><h5 class="font-bold">姓名：{{ student.stu_name }}</h5>
                        <h6 class="text-muted mb-0">
                            学号：{{ request.session.user_id }}
                        </h6>
                    </div>
                </div>
            </div>
        </div>
    {% elif user_label == 2 %}
        {# 当企业登录的时候显示组织的名称和账号 #}
        <div class="card">
            <div class="card-body py-4 px-5">
                <div class="d-flex align-items-center">
                    <div class="avatar avatar-xl">
                        <img src="{% static 'picture/5.jpg' %}" alt="Face female">
                    </div>
                    {# 加载企业的姓名和学号 #}
                    <div class="ms-3 name"><h5 class="font-bold">名称：{{ organization.name }}</h5>
                        <h6 class="text-muted mb-0">
                            账号：{{ request.session.user_id }}
                        </h6>
                    </div>
                </div>
            </div>
        </div>
    {% endif %}




{% endblock %}


{% block script_block %}
<script>
    $(document).ready(function() {
        $('#form').on('submit', function(e) {
            e.preventDefault();
            $.ajax({
                type: 'POST',
                url: "{% url 'organization:internship_detail' %}",
                data: $(this).serialize(),
                success: function(response) {
                    console.log(response);
                    if (response.code === 200) {
                        alert('发布实习成功');
                        window.location.href = "{% url 'organization:home' %}";
                    } else {
                        alert('发布实习失败');
                        window.location.href = "{% url 'organization:home' %}";
                    }
                },
                error: function(error) {
                    console.error('失败:', error);
                    alert('发布实习失败');
                }
            });
        });
    });
</script>
{% endblock %}

